﻿package src.game{
	import flash.display.MovieClip;
	import flash.events.Event;
	
	public class Letter extends MovieClip {
		private var speed:int;
		private var rotationSpeed:Number;
		private var isRemoved:Boolean = false;
		
		public function Letter(charCode:int) {
			this.content.selectable = false;
			this.content.embedFonts = true;
			this.content.text = String.fromCharCode(charCode);
		}
		
		public function setSpeed(speed:int):void {
			this.speed = speed;
		}
		
		public function setRotationSpeed(speed:Number):void {
			this.rotationSpeed = speed;
		}
		
		public function update():void {
			if (!isRemoved) move();
			else removeAnimation();
		}
		
		private function move():void {
			this.y += speed;
			this.rotation += rotationSpeed;
		}
		
		public function getText():String {
			return this.content.text;
		}
		
		private function removeAnimation():void {
			//trace ("removing " + this.content.text);
			this.height -= 5;
			this.width -=5;
			if (this.height < 10)
				remove();
		}
		
		public function setRemove(value:Boolean):void {
			isRemoved = value;
		}
		
		public function isBeingRemoved():Boolean {
			return isRemoved;
		}
		
		public function remove():void {
			//trace("remove event!" + this.content.text);
			dispatchEvent(new Event(Event.CLEAR));
		}

	}
	
}
